<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
	<!DOCTYPE html>
	<html lang="zh-cn" style="height: 100%">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
		<title>
			<?=VIEW_TITLE?>
		</title>
		<link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
		<link href="<?php echo base_url('/assets/css/'); ?>my_common.css?v=<?php echo time();?>" rel="stylesheet">
		<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
		<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
		<style>
			@media only screen and (max-width: 768px) {
				.oneCell {
					height: 300px;
					margin-bottom: 80px;
				}
				.cellMargin {
					margin-top: 30px;
					margin-bottom: 30px;
				}
				#edui31_body {
					width: 100%;
					max-width: 375px
				}
				.scroll-area {
					position: absolute;
					right: 4px;
					top: 10px;
					bottom: 10px;
					width: 35px;
					background: lightgray;
					border-radius: 5px;
					font-size: 20px;
					padding: 7px;
					color: darkgray
				}
				.xs-row-style {
					position: relative;
					overflow-y: scroll;
				}
				
				#edui1_iframeholder{
					min-height: 300px !important;
				}
			}
		</style>
	</head>

	<body>
		<?php
$this->load->view('admin_header.php');
?>
		<div class="container-fluid">
			<div id="main_div" style="position:relative;margin: 0 auto 10px auto;">

				<div class="row xs-row-style" style="">
					<div class="col-sm-6 col-md-6 col-xs-11">
						<div id="text_div" class="oneCell" style="overflow: scroll;overflow-x: hidden;margin: 10px auto 10px auto;">
							<div class="article_title">
								<h3 style="text-align: center;"><?php echo $original_article['title']; ?></h3>
							</div>
							<div class="article_content">
								<?php echo $original_article['article_html']; ?>
							</div>
							<div class="article_url" style="background-color: #f5f5f5;word-break:break-all;padding-left: 10px">
								<span style="white-space: nowrap;">原文链接:</span>
								<a href="<?php echo $original_article['url']; ?>">
									<?php echo $original_article['url']; ?>
								</a>
							</div>
						</div>
					</div>
					<div class="col-sm-6 col-md-6 col-xs-11" style="<?php if ($article_manager_info['is_translationed'] == 2) {
                echo 'display:none';
            } ?>">
						<div class="" style="overflow-x: hidden;margin: 15px auto 5px auto;">
							<input type="text" class="form-control" placeholder="请输入文章标题" id="title" value="<?php echo $translation_info['title'] ?>">
						</div>
						<div class="alert alert-warning" id="auto_save_info" style="padding:3px;margin-bottom: 3px;min-height: 30px;">
							
						</div>
						<div class="alert alert-warning" role="alert" style="margin: 5px 0 5px 0;">注意 : 正文翻译框仅填写译文，不需填写原文!</div>
						<div class="oneCell" style="overflow: scroll;overflow-x: hidden;margin: 0 auto 10px auto;">
							<script id="container" name="content" type="text/plain">
							</script>
						</div>
					</div>
					<div class="col-sm-6 col-md-6 col-xs-11" style="<?php if ($article_manager_info['is_translationed'] != 2) {
                echo 'display:none';
            } ?>">
						<div id="text_div" class="oneCell" style="overflow: scroll;overflow-x: hidden;margin: 10px auto 10px auto;">
							<div class="article_title">
								<h3 style="text-align: center;"><?php echo $translation_info['title']; ?></h3>
							</div>
							<div class="article_content">
								<?php echo $translation_info['article_html']; ?>
							</div>
							<div class="article_url" style="background-color: #f5f5f5;line-height: 40px;padding-left: 10px">
								原文链接:
								<a href="<?php echo $original_article['url']; ?>">
									<?php echo $original_article['url']; ?>
								</a>
							</div>
						</div>
					</div>
					<div class="visible-xs-inline-block scroll-area">
						需要滚动整个页面请滑动此处
					</div>
				</div>
			</div>
			<div class="hidden-xs" id="btn_group" style="position:fixed;top: 200px;z-index: 99999;<?php if ($article_manager_info['is_translationed'] == 2) {
             echo 'display:none';
         } ?>">
				<div>
					<button type="button" class="btn btn-default btn-sm" onclick="doTranslation(1)">
                <span class="glyphicon glyphicon-floppy-disk"></span> 保存
            </button>
				</div>
				<div style="margin-top: 10px;">
					<button type="button" class="btn btn-default btn-sm" onclick="faBiaoQueRen()">
                <span class="glyphicon glyphicon-open"></span> 提交
            </button>
				</div>
			</div>
			<div class="visible-xs-block" style="margin:20px 30px;text-align: right;
    	<?php if ($article_manager_info['is_translationed'] == 2) {
             echo 'display:none';
        } ?>
    	">
				<button type="button" class="btn btn-default" onclick="doTranslation(1)">
                <span class="glyphicon glyphicon-floppy-disk"></span> 保存
            </button>
				<button type="button" style="margin-left:20px;" class="btn btn-default" onclick="faBiaoQueRen()">
                <span class="glyphicon glyphicon-open"></span> 提交
            </button>
			</div>
			<div class="container-fluid" style="margin-bottom: 20px;">
				<div class="row">
					<div class="col-sm-3 col-md-3 col-lg-3" style="line-height: 34px;text-align: left;">
						<span class="glyphicon glyphicon-pencil" style="font-size: 20px;margin-right: 10px;"></span>翻译神技:
					</div>
					<div class="col-sm-6 col-md-6 col-lg-6">

						<div class="col-sm-4 col-md-4 col-lg-4">
							<a style="width: 100%" class="btn btn-info" href="http://fanyi.baidu.com/?aldtype=16047#auto/zh" type="button" target="_blank">百度翻译</a>
						</div>
						<div class="col-sm-4 col-md-4 col-lg-4">
							<a style="width: 100%" class="btn btn-info" href="http://fanyi.youdao.com/" type="button" target="_blank">有道翻译</a>
						</div>
						<div class="col-sm-4 col-md-4 col-lg-4">
							<a style="width: 100%" class="btn btn-info" href="http://translate.google.cn/" type="button" target="_blank">谷歌翻译</a>
						</div>
					</div>
					<!--            <div class="col-sm-3 col-md-3 col-lg-3" style="line-height: 34px;text-align: left;">-->
					<!--                更多翻译神技,敬请期待......-->
					<!--            </div>-->
				</div>

			</div>
		</div>
		<div class="modal fade" id="fabiao_model">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
						<h4 class="modal-title">确认提交</h4>
					</div>
					<div class="modal-body">
						<div>
							注意:确认提交后译文不能再修改!
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" onclick="doTranslation(2)">确认</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					</div>
				</div>
			</div>
		</div>
		<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
		<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
		<script src="<?php echo base_url('/assets/js/'); ?>yy_header_control.js?v=<?php echo time();?>"></script>
		<script type="text/javascript" src="<?php echo base_url('/assets/ueditor/'); ?>ueditor.config.js?a=1"></script>
		<script type="text/javascript" src="<?php echo base_url('/assets/ueditor/'); ?>ueditor.all.js"></script>
		<script type="text/javascript">
			var w_width = document.documentElement.clientWidth;
			var w_height = document.documentElement.clientHeight;
			var is_translationed = "<?php echo $article_manager_info['is_translationed']; ?>";
			//    $('#text_div').css('height', w_height - 90 + 'px');
			var right = 10;
			//    if (right <= 0) {
			//        right = 10;
			//    }
			$('#btn_group').css('right', right);
			$('#btn_group').css('top', w_height - 200);
			var auto_save = false;
			var hand_save = false;
			var ue = UE.getEditor('container', {
				initialFrameHeight: w_height - 260,
				enableAutoSave: false, //禁止自动保存
				autoSyncData: false, //自动同步编辑器要提交的数据
			});
			ue.ready(function() {
				ue.setContent('<?php echo str_replace("'","\'",str_replace(array("\r\n","\r","\n"),"",$translation_info["article_html"])) ?>');
			});

			function faBiaoQueRen() {
				$("#fabiao_model").modal("show");
			}

			function doTranslation(status) {
				if(status == 2) {
					$("#fabiao_model").modal("hide");
				}
				if(auto_save) {
					alert('自动保存中!请3秒后再试!');
					return false;
				}
				hand_save = true;
				var html = ue.getContent();
				var text = ue.getContentTxt();
				var title = $('#title').val();
				if(title == '') {
					alert('标题不能留空!');
					return false;
				}
				if(html == '' || text == '') {
					alert('内容不能留空!');
					return false;
				}
				ajaxLoading();
				$.ajax({
					url: "<?php echo site_url('/translators/save')?>",
					type: 'post',
					dataType: 'json',
					data: {
						html: html,
						text: text,
						title: title,
						manager_id: <?php echo $manager_id;?>,
						translation_id: <?php echo $translation_info['id'];?>,
						is_received: <?php echo $article_manager_info['is_received'];?>,
						original_user_id: <?php echo $original_article['original_user_id'];?>,
						status: status
					},
					success: function(data) {
						ajaxLoadEnd();
						hand_save = false;
						if(status == 1) {
							alert(data);
						}
						if(data == 'Success : 保存成功!' && status == 2) {
							alert('发布成功!');
							window.location.reload();
						}
					},
					error:function (xhr,errorText,error) {
						hand_save = false;
						ajaxLoadEnd();
						alert('notice:自动保存失败!请手动保存您的数据到本地文档,再尝试刷新页面!');
//						alert('保存失败了，error: '+ (errorText || error ));
						
					}
				});
			}

			function autoSave() {
				if(hand_save) {
					return false;
				}
				auto_save = true;
				var html = ue.getContent();
				var text = ue.getContentTxt();
				var title = $('#title').val();
				if(title == '') {
//					auto_save = false;
//					return false;
					title='默认标题'
				}
				if(html == '' || text == '') {
					auto_save = false;
					return false;
				}
				
				$('#auto_save_info').text('自动保存中....')
				$.ajax({
					url: "<?php echo site_url('/translators/save')?>",
					type: 'post',
					dataType: 'json',
					data: {
						html: html,
						text: text,
						title: title,
						manager_id: <?php echo $manager_id;?>,
						translation_id: <?php echo $translation_info['id'];?>,
						is_received: <?php echo $article_manager_info['is_received'];?>,
						status: 1
					},
					success: function(data) {
						auto_save = false;
						setTimeout(function () {
							$('#auto_save_info').text('')
						},1000)
						
						if(data != 'Success : 保存成功!') {
							alert('注意:自动保存失败!请手动保存您的数据到本地文档,再尝试刷新页面!');
						}
					},
					error:function () {
						auto_save = false;
							setTimeout(function () {
							$('#auto_save_info').text('')
						},1000)
						alert('notice:自动保存失败!请手动保存您的数据到本地文档,再尝试刷新页面!');
					}
				});
			}

//			if(is_translationed != 2) {
//				var int = self.setInterval("autoSave()", 10000);
//			}

			if(is_translationed != 2) {
				setInterval(function () {
					autoSave()
				},40000)
			}

			function logout() {
				$.ajax({
					url: '<?php echo site_url("admin/logout");?>',
					type: 'post',
					dataType: '',
					data: '',
					success: function(data) {
						window.location.href = '<?php echo site_url("admin/login");?>';
						return false;
					}
				});
			}

			function ajaxLoading() {
				$('#main_spinner').css({
					display: "block",
					width: "100%",
					height: $(window).height(),
					'z-index': 100001
				});
				$('#main_spinner_bg').css({
					display: "block",
					width: "100%",
					height: $(window).height(),
					'z-index': 100000
				});
			}

			function ajaxLoadEnd() {
				$("#main_spinner").hide();
				$("#main_spinner_bg").hide();
			}
			
		
		</script>
	</body>

	</html>